<?php
 defined("BASEDIR") or die();
 
 class Application_Controller_Adm_Treatment
 {
	protected $view, $request;
	public function __construct(Application_Router_Standard_Request $request)
	{
		$this->request = $request;
		$this->view = Application_View_ViewEngine::getInstance();
		if($request->show != "")
		{
			$actionName = $request->show."Action";
			if(method_exists($this, $actionName))
			{
				$this->$actionName();
				$this->view->assign("module", $request->action."_".$request->show."_admin");
			}
			else
				$this->view->assign("module", $request->action."_admin");
		}
		else
			$this->view->assign("module", $request->action."_admin");
	}
	
	protected function showtypesAction()
	{
		
		if ($this->request->show2 == "") {
			$db = Application_Model_DataBase::getInstance();
			$db->getTable("Rodzaj_zabiegu");
			$db->count();
			$db->execute();
			$num = $db->getResult();
			// $num[0] - Liczba wierszy w tabeli
			$pages = ceil($num[0]/constant("DISPLAY_LIMIT"));
			$this->view->assign("pages", $pages+1);
			$this->view->assign("totalUsers", $num[0]);
			if($this->request->offset == "") $offset = 0;
			else $offset = ($this->request->offset-1)*constant("DISPLAY_LIMIT");
			$db->getTable("Rodzaj_zabiegu");
			$db->limit(constant("DISPLAY_LIMIT"), $offset);
			$db->execute();
				while($u = $db->getResult())
				{
					
					$rodzaj[] = $u;
				}
				$this->view->assign("rodzajData", $rodzaj);
		} else {
			$db = Application_Model_DataBase::getInstance();
			
			$err = array();
			if(empty($err) && $this->request->rid != "")
			{
				$db->getTable("Rodzaj_zabiegu", "UPDATE");
				$db->setFields("rodzaj");
				$values = array($this->request->rodzaj);
				$db->setValues(implode(",", $values));
				$db->where("rid=".$this->request->rid);
				$num = $db->execute();
				$this->view->assign("added", $num);
			}
			$db->getTable("Rodzaj_zabiegu");
			$db->where("rid=".$this->request->id);
			$db->execute();
			$result = $db->getResult();
			$this->view->assign("det", 1);
			$this->view->assign("rodzaj", $result);
		}
		
	}
	protected function showdetailsAction()
	{
		
		if ($this->request->show2 == "") {
			$db = Application_Model_DataBase::getInstance();
			$db->getTable("Typy_zabiegow");
			$db->count();
			$db->execute();
			$num = $db->getResult();
			// $num[0] - Liczba wierszy w tabeli
			$pages = ceil($num[0]/constant("DISPLAY_LIMIT"));
			$this->view->assign("pages", $pages+1);
			$this->view->assign("totalUsers", $num[0]);
			if($this->request->offset == "") $offset = 0;
			else $offset = ($this->request->offset-1)*constant("DISPLAY_LIMIT");
			$db->getTable("Typy_zabiegow");
			$db->andTable("Rodzaj_zabiegu");
			$db->where("Rodzaj_zabiegu.rid=Typy_zabiegow.rid");
			$db->limit(constant("DISPLAY_LIMIT"), $offset);
			$db->execute();
				while($u = $db->getResult())
				{
					
					$typ[] = $u;
				}
				$this->view->assign("typData", $typ);
		} else {
			$db = Application_Model_DataBase::getInstance();
			
			$err = array();
			if(empty($err) && $this->request->tid != "")
			{
				$db->getTable("Typy_zabiegow", "UPDATE");
				$db->setFields("rid, typ");
				$values = array($this->request->rid, $this->request->typ);
				$db->setValues(implode(",", $values));
				$db->where("tid=".$this->request->tid);
				$num = $db->execute();
				$this->view->assign("added", $num);
			}
			$db->getTable("Rodzaj_zabiegu");
			$db->execute();
				while($u2 = $db->getResult())
				{
					
					$rodzaj[] = $u2;
				}
				$this->view->assign("rodzajData", $rodzaj);
			$db->getTable("Typy_zabiegow");
			$db->andTable("Rodzaj_zabiegu");
			$db->where("Rodzaj_zabiegu.rid=Typy_zabiegow.rid");
			$db->andWhere("tid=".$this->request->id);
			$db->execute();
			$result = $db->getResult();
			$this->view->assign("det", 1);
			$this->view->assign("typ", $result);
		}
		
	}
	
}
?>